using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace XnaDevRu.BulletX
{
	internal class BridgeTriangleRaycastCallback : TriangleRaycastCallback
	{
		CollisionWorld.RayResultCallback _resultCallback;
		CollisionObject _collisionObject;
		TriangleMeshShape _triangleMesh;

		public BridgeTriangleRaycastCallback(Vector3 from, Vector3 to,
								CollisionWorld.RayResultCallback resultCallback, CollisionObject collisionObject, TriangleMeshShape triangleMesh)
			: base(from, to)
		{
			_resultCallback = resultCallback;
			_collisionObject = collisionObject;
			_triangleMesh = triangleMesh;
		}

		public override float ReportHit(Vector3 hitNormalLocal, float hitFraction, int partId, int triangleIndex)
		{
			CollisionWorld.LocalShapeInfo shapeInfo = new CollisionWorld.LocalShapeInfo();
			shapeInfo.ShapePart = partId;
			shapeInfo.TriangleIndex = triangleIndex;

			CollisionWorld.LocalRayResult rayResult = new CollisionWorld.LocalRayResult
				(_collisionObject,
				 shapeInfo,
				 hitNormalLocal,
				 hitFraction);

			return _resultCallback.AddSingleResult(rayResult);
		}
	}
}
